package com.example.nanke.adapter

import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.example.gamecenter.R
import com.example.gamecenter.adapter.RecommendItem

class ListRecommendAdapter2(private val data: List<RecommendItem>) : RecyclerView.Adapter<ListRecommendAdapter2.ViewHolder>() {
    private lateinit var ctx :Context;
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        ctx = parent.context;
        val view = LayoutInflater.from(parent.context).inflate(R.layout.recommend_item2, parent, false)

        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = data[position]
        holder.bind(item)
    }

    override fun getItemCount(): Int {
        return data.size
    }

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        private val textView :TextView = itemView.findViewById(R.id.recommend_item_title2)
        private val imageView :ImageView = itemView.findViewById(R.id.recommend_item_image2)
        fun bind(item: RecommendItem) {
            textView.text = item.title
            //图片加载自己实现
            Glide.with(ctx!!).load(item.imageUrl).into(imageView);
        }
    }
}
